home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / unity331.zip / A86ERROR.PAS < prev    next >
Pascal/Delphi Source File  |  1991-09-19  |  3KB  |  132 lines

  1. Program A86ErrorFilter;
  2.  
  3. { you MUST run A86 with the +E command line option! }
  4.  
  5. Var
  6.   Source : Text;
  7.   FileName : String;
  8.   Index  : Integer;
  9.   SymbolError : Boolean;
  10.   LastLine : String;
  11.   LineNo : Integer;
  12.   Column : Integer;
  13.  
  14. Function Trim(Line : String) : String;
  15.  
  16. Begin
  17.   While (Line[1] = ' ') AND (Length(Line) > 0) Do Delete(Line,1,1);
  18.   While Line[Length(Line)] = ' ' Do Dec(Line[0]);
  19.   Trim := Line;
  20. End;
  21.  
  22. Procedure FindFileName(Var Source : Text;Var Line : String;Var Symbols : Boolean);
  23.  
  24. Var
  25.   Index : Integer;
  26.  
  27. Begin
  28.   Line := '';
  29.   While Not Eof(Source) do
  30.   Begin
  31.     LastLine := Line;
  32.     ReadLn(Source,Line);
  33.     If Pos('Error messages inserted into',Line) > 0 Then
  34.     Begin
  35.       Symbols := False;
  36.       Line := Trim(Line);
  37.       Index := Length(Line);
  38.       While(Line[Index]) <> ' ' Do Dec(Index);
  39.       Delete(Line,1,Index);
  40.       Exit;
  41.     End;
  42.     If Pos('Undefined symbols are listed in',Line) > 0 Then
  43.     Begin
  44.       Symbols := TRUE;
  45.       Line := Trim(Line);
  46.       Index := Length(Line);
  47.       While(Line[Index]) <> ' ' Do Dec(Index);
  48.       Delete(Line,1,Index);
  49.       Exit;
  50.     End;
  51.   End;
  52. End;
  53.  
  54. Function NextLine(Var Source : Text) : String;
  55.  
  56. Var
  57.   L : String;
  58.  
  59. Begin
  60.   If Not Eof(Source) Then
  61.   Begin
  62.     ReadLn(Source,L);
  63.     NextLine := L;
  64.     Inc(LineNo);
  65.   End;
  66. End;
  67.  
  68. Procedure ParseSymbolErrors(FileName : String);
  69.  
  70. Var
  71.   Line   : String;
  72.   Message : String;
  73.  
  74. Begin
  75.   Assign(Source,FileName);
  76.   Reset(Source);
  77.   While Not Eof(Source) Do
  78.   Begin
  79.     ReadLn(Source,Line);
  80.     Line := Trim(Line);
  81.     Index := Pos(' ',Line);
  82.     If Index > 0 Then
  83.     Begin
  84.       Message := 'Undefined symbol: '+Copy(Line,1,Pred(Index));
  85.       Delete(Line,1,Index+3);
  86.       WriteLn(Line,', 0, 0, ',Message);
  87.     End;
  88.   End;
  89.   Close(Source);
  90.   Erase(Source);
  91. End;
  92.  
  93. Procedure ParseOtherErrors(FileName : String);
  94.  
  95. Var
  96.   Line   : String;
  97.  
  98. Begin
  99.   Assign(Source,FileName);
  100.   Reset(Source);
  101.   LineNo := 0;
  102.   Line := NextLine(Source);
  103.   If Pos('~',Line) = 1 Then Dec(LineNo);
  104.   While Not Eof(Source) Do
  105.   Begin
  106.     Line := NextLine(Source);
  107.     If Line[Length(Line)] = '~' Then
  108.     Begin
  109.       Dec(LineNo);  { adjust for inserted error message }
  110.       Index := Pred(Length(Line));
  111.       While Line[Index] <> '~' Do Dec(Index);
  112.       Column := Index;
  113.       Delete(Line,1,Index);
  114.       Dec(Line[0]);
  115.       WriteLn(Trim(LastLine),', ',Succ(LineNo),', ',Column,', ','Error #',Line);
  116.     End;
  117.   End;
  118.   Close(Source);
  119.   Erase(Source);
  120. End;
  121.  
  122. Begin
  123.   Assign(Source,ParamStr(1));
  124.   Reset(Source);
  125.   FindFileName(Source,FileName,SymbolError);
  126.   Close(Source);
  127.   If FileName = '' Then Exit;
  128.   If SymbolError
  129.     Then ParseSymbolErrors(FileName)
  130.   Else ParseOtherErrors(FileName);
  131. End.
  132.